package com.it.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.it.Mapper.CustomerMapper2;
import com.it.pojo.Customer;
import com.it.service.CustomerService2;
import org.springframework.stereotype.Service;

@Service
public class CustomerSerivceImpl2 extends ServiceImpl<CustomerMapper2, Customer>implements CustomerService2 {
    @Override
    public Page<Customer> getCustomerList(String search, Integer page, Integer pageSize) {
        Page<Customer> pageParam = new Page<>(page-1, pageSize);
        LambdaQueryWrapper<Customer> queryWrapper = new LambdaQueryWrapper<>();

        if (StringUtils.isNotBlank(search)) {
            queryWrapper.like(Customer::getName, search)
                    .or()
                    .like(Customer::getContactPerson, search)
                    .or()
                    .like(Customer::getContactPhone, search);
        }

        return this.page(pageParam, queryWrapper);
    }

    @Override
    public boolean createCustomer(Customer customer) {
        return this.save(customer);
    }

    @Override
    public boolean updateCustomer(Integer id, Customer customer) {
        customer.setCustomerId(id);
        return this.updateById(customer);
    }

    @Override
    public boolean deleteCustomer(Integer id) {
        return this.removeById(id);
    }
}
